/*
 * Camera.cpp
 *
 *  Created on: Jan 11, 2014
 *      Author: nick
 */

#include "Camera.h"

Camera::Camera() {
	box.x = 0;
	box.y = 0;

	box.h = SCREEN_HEIGHT;
	box.w = SCREEN_WIDTH - (2 * TILE_WIDTH);
}
;

Camera::Camera(int x, int y, int h, int w, int newType) {
	box.x = x;
	box.y = y;
	box.h = h;
	box.w = w;
	type = newType;
}
;

Camera::~Camera() {
}
;

void Camera::handleInput() {
	//If a key was pressed
	if (event.type == SDL_KEYDOWN) {
		//Adjust the velocity
		switch (event.key.keysym.sym) {
		case SDLK_UP:
			yVel -= CAMERA_SPEED;
			break;
		case SDLK_DOWN:
			yVel += CAMERA_SPEED;
			break;
		case SDLK_LEFT:
			xVel -= CAMERA_SPEED;
			break;
		case SDLK_RIGHT:
			xVel += CAMERA_SPEED;
			break;
		default:
			break;
		}
	}

	//If a key was released
	else if (event.type == SDL_KEYUP) {
		//Adjust the velocity
		switch (event.key.keysym.sym) {
		case SDLK_UP:
			yVel += CAMERA_SPEED;
			break;
		case SDLK_DOWN:
			yVel -= CAMERA_SPEED;
			break;
		case SDLK_LEFT:
			xVel += CAMERA_SPEED;
			break;
		case SDLK_RIGHT:
			xVel -= CAMERA_SPEED;
			break;
		default:
			break;
		}
	}
}
;

void Camera::move() {
	//Move the dot left or right
	box.x += xVel;

	//If the dot went too far to the left or right or touched a wall
	if ((box.x < 0) || (box.x + box.w > LEVEL_WIDTH)) {
		//move back
		box.x -= xVel;
	}

	//Move the dot up or down
	box.y += yVel;

	//If the dot went too far up or down or touched a wall
	if ((box.y < 0) || (box.y + box.h > LEVEL_HEIGHT)) {

		//move back
		box.y -= yVel;
	}
}
;

